package cn.lhl01.sys.entity.po;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * <p>
 * 用户表
 * </p>
 *
 * @author lhl
 * @since 2023-02-08
 */
@Getter
@Setter
@Accessors(chain = true)
@TableName("sys_user")
@ToString
public class SysUser implements Serializable, UserDetails {

	private static final long serialVersionUID = 1L;

	@TableId(value = "id", type = IdType.AUTO)
	private Long id;

	/**
	 * 名
	 */
	@TableField("username")
	private String username;

	/**
	 * 密码
	 */
	@TableField("password")
	private String password;


	/*角色的*/
	@TableField(exist = false)
	private List<SysRole> sysRoleList = new ArrayList<>();
	/*资源的*/
	@TableField(exist = false)
	private List<SysMenu> sysMenuList = new ArrayList<>();


	/**
	 * 账户未失效
	 *
	 * @return
	 */
	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	/**
	 * 账户未锁定
	 *
	 * @return
	 */
	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	/**
	 * 密码未失效
	 *
	 * @return
	 */
	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	/**
	 * 可用
	 *
	 * @return
	 */
	@Override
	public boolean isEnabled() {
		return true;
	}

	/* 获取当前用户对应的 资源 权限列表 */
	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		return sysMenuList;
	}
}
